using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Affirma.ThreeSharp.Wrapper;
using System.Xml;

namespace CloudDrive.S3
{
    public class StringList : IList<string>
    {
        private List<string> _List;
        private StringComparer _Comparer;
        public StringList(StringComparer comparer)
        {
            _Comparer = comparer;
            _List = new List<string>();
        }
        #region IList<T> Members

        public int IndexOf(string item)
        {
            for (int i = 0; i < _List.Count; i++)
            {
                if (_Comparer.Equals(_List[i], item))
                    return i;
            }
            return -1;
        }

        public void Insert(int index, string item)
        {
            _List.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            _List.RemoveAt(index);
        }

        public string this[int index]
        {
            get
            {
                return _List[index];
            }
            set
            {
                _List[index] = value;
            }
        }

        #endregion

        #region ICollection<T> Members

        public void Add(string item)
        {
            if (!Contains(item))
                _List.Add(item);
        }

        public void Clear()
        {
            _List.Clear();
        }

        public bool Contains(string item)
        {
            for (int i = 0; i < _List.Count; i++)
            {
                if (_Comparer.Equals(_List[i], item))
                    return true;
            }
            return false;
        }

        public void CopyTo(string[] array, int arrayIndex)
        {
            _List.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return _List.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(string item)
        {
            for (int i = 0; i < _List.Count; i++)
            {
                if (_Comparer.Equals(_List[i], item))
                {
                    _List.RemoveAt(i);
                    return true;
                }
            }
            return false;
        }

        #endregion

        #region IEnumerable<T> Members

        public IEnumerator<string> GetEnumerator()
        {
            return _List.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _List.GetEnumerator();
        }

        #endregion
    }
}
